package controllers

import (
	"app/model"
	"app/service"
	"github.com/google/uuid"

	"github.com/gin-gonic/gin"
)

type UserController struct {
}

func (u UserController) GetUserInfo(c *gin.Context) {
	id := c.Param("id")

	Failed(4004, c, "没有相关信息"+id)
}

// Save @Summary 保存用户信息
// @Description 保存用户信息
// @Tags User
// @Accept  json
// @Produce  json
// @Param user body model.UserInfo true "用户信息"
// @Success 200 {object} model.JobInfo
// @Router /users/save [post]
func (u UserController) Save(c *gin.Context) {
	var info model.UserInfo
	if err := c.ShouldBindJSON(&info); err != nil {
		Failed(1, c, err.Error())
		return
	}
	info.ID = uuid.NewString()
	service.UserService{}.Save(info)
	Succeed(1, c, nil, 1, nil)

}

// Login @Summary 用户登录
// @Description 用户登录
// @Tags User
// @Accept  json
// @Produce  json
// @Param user body model.UserInfo true "用户信息"
// @Success 200 {object} model.JobInfo
// @Router /users/login [post]
func (u UserController) Login(c *gin.Context) {
	var info model.UserInfo
	if err := c.ShouldBindJSON(&info); err != nil {
		Failed(1, c, err.Error())
		return
	}
	user := service.UserService{}.Login(info.UserName, info.Password)
	Succeed(1, c, user, 1, nil)

}
